package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsUser;
import com.qf.pojo.DtsUserAccount;
import com.qf.service.DtsUserAccountService;
import com.qf.service.DtsUserService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Zwnan
 */
@RestController
@RequestMapping("/admin/user")
@CrossOrigin
public class UserController {

    @Autowired
    private DtsUserService dtsUserService;

    @Autowired
    private DtsUserAccountService dtsUserAccountService;

    @RequiresPermissionsDesc(menu = {"用户管理","会员管理"},button = "查询")
    @RequiresPermissions("admin:user:list")
    @GetMapping("/list")
    public Object userList(@RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "20") Integer limit
            ,@RequestParam(defaultValue = "add_time") String sort
            ,@RequestParam(defaultValue = "desc") String order){
        IPage<DtsUser> iPage = dtsUserService.selectByPage(page,limit,sort,order);
        long total = iPage.getTotal();
        List<DtsUser> records = iPage.getRecords();

        Map map = new HashMap();
        map.put("total", total);
        map.put("items", records);


        return ResponseUtil.ok(map);
    }
    @RequiresPermissionsDesc(menu = {"用户管理","会员管理"},button = "审批")
    @RequiresPermissions("admin:user:approveAgency")
    @PostMapping("/approveAgency")
    public Object approveAgency(){

        return ResponseUtil.ok();
    }
    @RequiresPermissionsDesc(menu = {"用户管理","会员管理"},button = "推广")
    @RequiresPermissions("admin:user:detailApprove")
    @GetMapping("/detailApprove")
    public Object detailApprove(@RequestParam Integer id){
       DtsUserAccount dtsUserAccount = dtsUserAccountService.findById(id);
        Map map = new HashMap();
        map.put("data", dtsUserAccount);

        return ResponseUtil.ok(map);
    }




}
